
import 'dart:async';

class PersistTimer {
  final Duration duration;
  final Function onCall;
  final Function onEnd;
  Timer timer;

  PersistTimer({ 
    this.duration,
    this.onCall,
    this.onEnd,
  });

  void start() {
    if(onCall != null) onCall();
    if(timer?.isActive == true) timer.cancel();
    timer = Timer(duration, (){
      if(onEnd != null) onEnd();
    });
  }

  void dispose() {
    if(timer?.isActive == true) timer.cancel();
  }
}